import React, { Component } from "react";
import "./index.css";
export default class Footer extends Component {
  checkAllTodo = (e) => {
    this.props.checkAllTodo(e.target.checked);
  };
  clearDone=()=>{
    this.props.clearDone()
  }
  render() {
    const { todos } = this.props;
    //计算已完成
    const donecount = todos.filter((todo) => todo.done).length;
    const total = todos.length;

    const isAll = (donecount === total ? true : false) && total > 0;

    return (
      <div className="todo-footer">
        <label>
          <input
            type="checkbox"
            checked={isAll}
            onChange={this.checkAllTodo}
          />
        </label>
        <span>
          <span>已完成{donecount}</span> / 全{total}
        </span>
        <button onClick={this.clearDone} className="btn btn-danger">清除已完成任务</button>
      </div>
    );
  }
}
